/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package helper;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Ku81
 */
public class MD5 {
    public static String getMd5(String str){
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("MD5");
            byte[] messages = md.digest(str.getBytes());
            BigInteger bigInt = new BigInteger(1, messages);
            String hashText = bigInt.toString(16);
            while(hashText.length() <32){
                hashText = "0"+hashText;
            }
            return hashText;
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(MD5.class.getName()).log(Level.SEVERE, null, ex);
            return str;
        }
    }
}
